import { makeExecutableSchema } from 'graphql-tools';
import { graphql } from "graphql";

module.exports = [
  {
    url: '/graphql',
    controller: function *() {
      this.body = require("../graphiql");
    }
  },
  {
    url: '/graphql',
    method: 'post',
    controller: function *(request) {
      var body = yield request.getBody();
      console.log(body);
      var ret = yield graphql(schema, body.query, {}, {});
      console.log(ret);
      this.body = ret;
    }
  }
];

var schema = makeExecutableSchema({
  typeDefs: 
  `
    type Person {
      name: String
      id:   String
      age: Int
    }
    type RootQuery {
      person(id: String) : Person
    }
    schema {
      query: RootQuery
    }

  `
  ,
  resolvers: {
    RootQuery: {
      person: function () {
        return {name: 'jack', age: 10, id: 0}
      }
    }
  }
});
